/* 
 * File:   ucgrid1d.h
 * Author: oddi
 *
 * Created on October 3, 2010, 1:17 PM
 */

#ifndef _UCGRID1D_H
#define	_UCGRID1D_H

#include "inc/core/global_definitions.h"
#include "inc/core/particles.h"
#include "inc/core/poisson1d.h"


//Uniform carthesian grid 1d
//stores density of charge particles,
//values of electric and magnetic fields

#ifdef	__cplusplus
extern "C" {
#endif

#define CELLTYPE_ERROR     -1
#define CELLTYPE_REGULAR    1
#define CELLTYPE_LEFTBOUND  2
#define CELLTYPE_RIGHTBOUND 3

    typedef struct struct_init_grid1d
    {
        floatdig min_z;
        floatdig max_z;
        floatdig l_phi;
        floatdig r_phi;
        floatdig cell_size;
    } init_ucgrid1d;

    typedef struct struct_ucgrid1d {
        floatdig grid_cell_size;
        int num_of_cells;
        floatdig *rho;
        floatdig *E;
        floatdig *B;
        floatdig* phi;
        poisson1d poisson_solver;


#ifdef DEBUG
        floatdig *rho_test;
#endif

        floatdig* cellnums;

        init_ucgrid1d parameters;

    } ucgrid1d;

    typedef ucgrid1d* pucgrid1d;

    void ucgrid1d_init_grid(init_ucgrid1d*, ucgrid1d*);
    void ucgrid1d_clear_grid(ucgrid1d*);
    void ucgrid1d_calc_charge_density_from_particles_distr(particles_set*, ucgrid1d*);
    void ucgrid1d_calc_static_fields(ucgrid1d*);
    void ucgrid1d_calc_phi_from_charge_density(ucgrid1d*);
    void ucgrid1d_get_cell_center_pos(ucgrid1d*, int cell_num, floatdig* pos);
    int ucgrid1d_search_neighbor_cells(ucgrid1d*, floatdig pos, int *left, int *right);
    int ucgrid1d_get_cell_boundaries(ucgrid1d* grid, int cell_num, floatdig * left, floatdig * right);
    void ucgrid1d_calc_currents_from_particles_distribution(particles_set* set, ucgrid1d* grid);
    


#ifdef DEBUG
    int ucgrid1d_distribute_particles_debug(particles_set* set, ucgrid1d* grid);
    int ucgrid1d_distribute_phi_debug(ucgrid1d*);
    int get_fft_over_grid_charge_density(ucgrid1d*);
    void ucgrid1d_distribute_rho_debug(particles_set*, ucgrid1d* grid);
    void ucgrid1d_print_rho_into_file_debug(char*, ucgrid1d*);
    void ucgrid1d_print_phi_into_file_debug(char*, ucgrid1d*);
    void ucgrid1d_print_E_into_file_debug(char*, ucgrid1d*);
#endif




#ifdef	__cplusplus
}
#endif

#endif	/* _UCGRID1D_H */

